package com.pfzy.utildemo.activity.record.soundrecord;

import android.content.SharedPreferences;
import android.text.TextUtils;

import com.pfzy.utildemo.utils.CommonUtil;

/**
 * 录音模式
 */
class SoundRecordSwitch {
    private static String mAudioFormat;// 录音格式
    private static volatile SharedPreferences mSharedPreferences;

    SoundRecordSwitch() { }

    public static void switchAAC(boolean aac) {
        getSharedPreferences().edit().putBoolean("use_aac", aac).apply();
    }

    /**
     * 切换aac 和 mp3格式
     * @return
     */
    public static boolean isUseAAC() {
        if (TextUtils.isEmpty(mAudioFormat)) {
            mAudioFormat = getSharedPreferences().getBoolean("use_aac", false) ? "aac" : "mp3";
        }
        return TextUtils.equals(mAudioFormat, "aac");
    }

    private static SharedPreferences getSharedPreferences() {
        if (mSharedPreferences == null) {
            synchronized (SoundRecordSwitch.class) {
                if (mSharedPreferences == null) {
                    mSharedPreferences = CommonUtil.getContext().getSharedPreferences("use_aac", 0);
                }
            }
        }
        return mSharedPreferences;
    }
}
